package com.xyz.wll.es.manager.ui.model;

import lombok.Data;

@Data
public class PageCursor {
    private String index;
    private int size;
    private int from;
    private int hits;
    private int total;

    public boolean isFirstPage() {
        return from == 0;
    }

    public boolean isLastPage() {
        return from + size >= total;
    }

    public void gotoFirstPage() {
        from = 0;
        size = 100;
    }

    public void gotoLastPage() {
        if(total < size) {
            from = 0;
        } else {
            if(total%size==0) {
                from = total - size;
            } else {
                from = total/size*size;
            }
        }
    }

    public void gotoNextPage() {
        if(!isLastPage()) {
            from += size;
        }
    }

    public void gotoPriorPage() {
        if(!isFirstPage()) {
            from -= size;
        }
    }

    public int getCurrentPage() {
        return from/size + 1;
    }

    public int getTotalPages() {
        return (total+size-1)/size;
    }
}
